package biolabs.space;

import biolabs.space.BooleanViewGrid.Predicate;

/**
 * A helper class for discrete grids.
 *
 * @author Tomas Mikula
 */
public class Grids {

	public static final Predicate<Object> IsNotNull = new Predicate<Object>() {
		@Override
		public boolean asBoolean(Object obj) {
			return obj != null;
		}
	};

	public static final Predicate<Object> IsNull = new Predicate<Object>() {
		@Override
		public boolean asBoolean(Object obj) {
			return obj == null;
		}
	};

	/**
	 * Returns a boolean read-only view of this grid.
	 * Query to the returned grid at position {@code p} returns
	 * {@code true} iff {@code this} grid contains non-{@code null}
	 * object at position {@code p}.
	 */
	public static
	<T, U extends T, P extends DiscretePosition<P,C>, C extends ContinuousPosition<C,P>>
	Grid<Boolean, P, C> asBooleanGrid(Grid<U, P, C> g, BooleanViewGrid.Predicate<? super T> tr){
		return new BooleanViewGrid<U, P, C>(g, tr);
	}
}
